package com.fwx.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fwx.dao.EmpDao;
import com.fwx.entity.Emp;
import com.fwx.service.EmpService;
import com.fwx.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: springBoot06
 * @description:
 * @author: 范文轩
 * @create: 2024-07-15 08:55
 **/

@Service
public class EmpServiceImpl implements EmpService {
    
    @Autowired
    private EmpDao empDao;
    
    @Override
    public R insert(Emp emp) {
        int row = empDao.insert(emp);
        if (row > 0){
            return new R(200,"添加成功",row);
        }
        return new R(500,"添加失败",null);
    }

    @Override
    public R updateById(Emp emp) {
        int row = empDao.updateById(emp);
        if (row > 0){
            return new R(200,"修改成功",row);
        }
        return new R(500,"修改失败",null);
    }

    @Override
    public R deleteById(Integer empno) {
        int row = empDao.deleteById(empno);
        if (row > 0){
            return new R(200,"删除成功",row);
        }
        return new R(500,"删除失败",null);
    }

    @Override
    public R selectAll(Integer current, Integer size) {
        Page<Emp> page = new Page<>(current,size);
        QueryWrapper<Emp> wrapper = new QueryWrapper<>();
        Page<Emp> empPage = empDao.selectAll(page,wrapper);
        if (empPage.getSize() > 0){
            return new R(200,"查询成功",empPage.getRecords());
        }
        return new R(500,"很抱歉，没有找到相关信息",null);
    }

    @Override
    public R selectByEmpNo(Integer empno) {
        Emp emp = empDao.selectByEmpNo(empno);
        if (emp != null){
            return new R(200,"查询成功",emp);
        }
        return new R(500,"很抱歉，没有找到该用户",null);
    }
}
